import { reqGetConditionList, reqGetSearchLabelList,reqGetScreenMan,reqGetScreenWomen } from "@/api";

const state = {
  searchList: {},
  conditionList: {},
  userData:[],
};

const getters = {
  getSearchData(state, inpValue) {
    console.log(state, inpValue);
    const { conditionList } = state;
    const searchUser = conditionList.list.find((item) => {
      return item.nickname === inpValue;
    });

    return searchUser;
  },
};

const actions = {
  getSearchLabelList({ commit }) {
    reqGetSearchLabelList().then((res) => {
      commit("SETSEARCHLABELLIST", res.data.data);
    });
  },
  getConditionList({ commit }, index) {
    reqGetConditionList(index).then((res) => {
      commit("SETCONDITIONLIST", res.data.data);
    });
  },
  // 筛选条件男
  getScreenMan({ commit }) {
    reqGetScreenMan().then((res) => {
      commit("SETSCREENMAN", res.data.data);
    });
  },
  // 筛选条件女
  getScreenWomen({ commit }) {
    reqGetScreenWomen().then((res) => {
      commit("SETSCREENWOMEN", res.data.data);
    });
  },
};

const mutations = {
  SETSEARCHLABELLIST(state, searchList) {
    state.searchList = searchList;
  },
  SETCONDITIONLIST(state, conditionList) {
    state.conditionList = conditionList;
  },
  SETSCREENMAN(state, conditionList) {
    state.conditionList = conditionList;
  },
  SETSCREENWOMEN(state, conditionList) {
    state.conditionList = conditionList;
  },
  GETUSERDATA(state,userData){
    state.userData.push(userData);
  }
};

export default {
  state,
  getters,
  actions,
  mutations,
};
